package com.iswoak.netctoss.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.iswoak.netctoss.dao.ModuleInfoDao;
import com.iswoak.netctoss.entity.ModuleInfo;
import com.iswoak.netctoss.util.DBUtil;

public class ModuleInfoDaoImpl implements ModuleInfoDao{
	@Override
	public List<ModuleInfo> findAll() {
		//创建连接
		Connection conn=DBUtil.getConnection();
		PreparedStatement ps=null;
		List<ModuleInfo> list=null;
		String sql="select * from module_info";
		try {
			ps=conn.prepareStatement(sql);
			ResultSet rs=ps.executeQuery();
			list=new ArrayList<ModuleInfo>();
			//处理结果集
			while(rs.next()){
				list.add(new ModuleInfo(rs.getInt("module_id"), rs.getString("name")));
			}
			rs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBUtil.closeConnectionAndPreparedStatement(conn, ps);
		}
		return list;
	}
}
